#include <linux/module.h>
#include<linux/timer.h>
MODULE_LICENSE("GPL");
struct timer_list my_timer1; //声明动态定时器

// 定义动态定时器到期处理函数在此只有显示功能不做任何处理
void my_timer1_function(unsigned long data)
{
	struct timer_list* mytimer;
	int result;
	
	printk("In the my_timer1_function\n");
	mytimer = (struct timer_list *)data;
	printk("the current jiffies is:%ld\n", jiffies);    //显示当前节拍数
	printk("the expires of my_timer1 is:%ld\n", mytimer->expires); //显示字段expires
	result=timer_pending(mytimer);                  //测试定时器状态
	printk("the timer_pending result of my_timer1 is: %d\n", result); //显示测试结果
	
	result = mod_timer_pending(&my_timer1,mytimer->expires+10);

	printk("the mod result of my_timer1: %d\n",result);
	printk("the expires of my_tmer1 is %d\n",mytimer->expires);

}

int __init timer_pending_init(void)
{
	printk("my_timer1 will be created.\n");
	printk("the current jiffies is :%ld\n", jiffies); //显示当前节拍数
	init_timer(&my_timer1);                              //初始化动态定时器
	my_timer1.expires = jiffies + 1*HZ;
	my_timer1.data = &my_timer1;
	my_timer1.function = my_timer1_function;
	add_timer(&my_timer1);                               //激活定时器
	int result=timer_pending(&my_timer1);           //测试定时器状态
	printk("the timer_pendng result of my_timer1 is: %d\n", result); //显示测试结果

	int res = mod_timer_pending(&my_timer1,my_timer1.expires +10);
	printk("the result of mod timer pending is %d\n",res);
	printk("the expires of my_timer1 : %d\n",my_timer1.expires);
	printk("my_timer1 init.\n");
return 0;
}

void __exit timer_pending_exit(void)
{
	printk("Goodbye timer_pending\n");
	del_timer(&my_timer1); //删除定时器变量
}

module_init(timer_pending_init);
module_exit(timer_pending_exit);
